<?php
function make_insert_sql($table,$data)
{
	$sql = '';
	$first = true;
	$cols = '';
	$vals = '';
	foreach($data as $key => $val)
	{
		if ($first)
		{
			$cols.= "`$key`";
			$vals.= "'".mysql_escape_string($val)."'";
			$first = false;
		}
		else
		{
			$cols .= ",`$key`";
			$vals.= ",'".mysql_escape_string($val)."'";
		}
	}
	$sql = "INSERT INTO `$table` ($cols) VALUES($vals) ";
	return $sql;
}

function make_select_sql($table,$data)
{
	$first = true;
	$cond = '';
	foreach($data as $key => $val)
	{
		if ($first)
		{
			$cond.= "`$key` = '$val' ";
			$first = false;
		}
		else
		{
			$cond.= "AND `$key` = '$val' ";
		}
	}
	$sql = "SELECT * FROM `$table` WHERE $cond ";
	return $sql;
}

function make_update_sql($table,$data,$cond_arr)
{
	$first = true;
	$values = '';
	foreach($data as $key => $val)
	{
		if ($first)
		{
			$values.= "`$key` = '$val' ";
			$first = false;
		}
		else
		{
			$values.= ", `$key` = '$val' ";
		}
	}
	
	$first = true;
	$cond = '';
	foreach($cond_arr as $key => $val)
	{
		if ($first)
		{
			$cond.= "`$key` = '$val' ";
			$first = false;
		}
		else
		{
			$cond.= "AND `$key` = '$val' ";
		}
	}
	$sql = "UPDATE `$table` SET $values WHERE $cond ";
	return $sql;
}

?>